package com.itheima.多态;

public class Test03 {
    /*
    定义动物类 属性：年龄，颜色 生成空参有参构造，set和get方法
    行为：eat(String something)方法(无具体行为,不同动物吃的方式和东西不一样,something表示吃的东西)
定义狗类继承动物类，行为：eat(String something)方法,看家lookHome方法(无参数)
定义猫类继承动物类，行为：eat(String something)方法,逮老鼠catchMouse方法(无参数)
定义Person类 生成空参有参构造，set和get方法 属性：（姓名，年龄）
行为：keepPet( ????? ,String something)方法​
功能：喂养【宠物狗】和【宠物猫】，问号处自己思考，something表示喂养的东西
定义测试类，使用Perosn对象调用keepPet方法，实现运行结果
运行结果：
年龄为30岁的老王养了一只黑颜色的2岁的宠物
2岁的黑颜色的狗两只前腿死死的抱住骨头猛吃
年龄为25岁的老李养了一只灰颜色的3岁的宠物
3岁的灰颜色的猫眯着眼睛侧着头吃鱼
     */
    public static void main(String[] args) {
        new Person1("老王",30).keepPet(new Dog(2,"黑"),"骨头");
        new Person1("老李",25).keepPet(new Cat(3,"灰"),"鱼头");
    }
}

class Animal {
    private int age;
    private String color;

    public Animal() {
    }

    public Animal(int age, String color) {
        this.age = age;
        this.color = color;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void eat(String something) {
    }
}

class Person1 extends Animal {
    private String name;
    private int age;

    public Person1() {
    }

    public Person1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int getAge() {
        return age;
    }

    @Override
    public void setAge(int age) {
        this.age = age;
    }

    public void keepPet(Animal a, String something) {
        System.out.println("年龄为"+getAge()+"岁的"+name+"养了一只"+a.getColor()+"颜色的"+a.getAge()+"岁的宠物");
        a.eat(something);
    }
}

class Dog extends Animal {
    public Dog() {
    }

    public Dog(int age, String color) {
        super(age, color);
    }

    public void eat(String something) {
        System.out.println(getAge() + "岁的" + getColor() + "颜色的狗两只前腿死死的抱住" + something + "猛吃");
    }

    public void lookHome() {
        System.out.println("看家");
    }
}

class Cat extends Animal {

    public Cat() {
    }

    public Cat(int age, String color) {
        super(age, color);
    }

    public void eat(String something) {
        System.out.println(getAge() + "岁的" + getColor() + "颜色的猫眯着眼睛侧着头" + something);
    }

    public void catchMouse() {
        System.out.println("猫抓老鼠");
    }
}